package b.n;

import androidx.lifecycle.CompositeGeneratedAdaptersObserver;
import androidx.lifecycle.FullLifecycleObserverAdapter;
import androidx.lifecycle.ReflectiveGenericLifecycleObserver;
import androidx.lifecycle.SingleGeneratedAdapterObserver;
import b.c.a.b.b.c;
import b.n.d.b;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/* compiled from: LifecycleRegistry */
public class h extends d {
    public b.c.a.b.a<f, a> a = new b.c.a.b.a();
    public b b;
    public final WeakReference<g> c;
    public int d = 0;
    public boolean e = false;
    public boolean f = false;
    public ArrayList<b> g = new ArrayList();

    /* compiled from: LifecycleRegistry */
    public static class a {
        public b a;
        public e b;

        public a(f fVar, b bVar) {
            e fullLifecycleObserverAdapter;
            Map map = j.a;
            boolean z = fVar instanceof e;
            boolean z2 = fVar instanceof b;
            if (z && z2) {
                fullLifecycleObserverAdapter = new FullLifecycleObserverAdapter((b) fVar, (e) fVar);
            } else if (z2) {
                fullLifecycleObserverAdapter = new FullLifecycleObserverAdapter((b) fVar, null);
            } else if (z) {
                fullLifecycleObserverAdapter = (e) fVar;
            } else {
                Class cls = fVar.getClass();
                if (j.c(cls) == 2) {
                    List list = (List) j.b.get(cls);
                    int i = 0;
                    if (list.size() == 1) {
                        fullLifecycleObserverAdapter = new SingleGeneratedAdapterObserver(j.a((Constructor) list.get(0), fVar));
                    } else {
                        c[] cVarArr = new c[list.size()];
                        while (i < list.size()) {
                            cVarArr[i] = j.a((Constructor) list.get(i), fVar);
                            i++;
                        }
                        fullLifecycleObserverAdapter = new CompositeGeneratedAdaptersObserver(cVarArr);
                    }
                } else {
                    fullLifecycleObserverAdapter = new ReflectiveGenericLifecycleObserver(fVar);
                }
            }
            this.b = fullLifecycleObserverAdapter;
            this.a = bVar;
        }

        public void a(g gVar, b.n.d.a aVar) {
            b c = h.c(aVar);
            this.a = h.e(this.a, c);
            this.b.d(gVar, aVar);
            this.a = c;
        }
    }

    public h(g gVar) {
        this.c = new WeakReference(gVar);
        this.b = b.INITIALIZED;
    }

    public static b c(b.n.d.a aVar) {
        int ordinal = aVar.ordinal();
        if (ordinal != 0) {
            if (ordinal != 1) {
                if (ordinal == 2) {
                    return b.RESUMED;
                }
                if (ordinal != 3) {
                    if (ordinal != 4) {
                        if (ordinal == 5) {
                            return b.DESTROYED;
                        }
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("Unexpected event value ");
                        stringBuilder.append(aVar);
                        throw new IllegalArgumentException(stringBuilder.toString());
                    }
                }
            }
            return b.STARTED;
        }
        return b.CREATED;
    }

    public static b e(b bVar, b bVar2) {
        return (bVar2 == null || bVar2.compareTo(bVar) >= 0) ? bVar : bVar2;
    }

    public static b.n.d.a i(b bVar) {
        int ordinal = bVar.ordinal();
        if (ordinal == 0 || ordinal == 1) {
            return b.n.d.a.ON_CREATE;
        }
        if (ordinal == 2) {
            return b.n.d.a.ON_START;
        }
        if (ordinal == 3) {
            return b.n.d.a.ON_RESUME;
        }
        if (ordinal != 4) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Unexpected state value ");
            stringBuilder.append(bVar);
            throw new IllegalArgumentException(stringBuilder.toString());
        }
        throw new IllegalArgumentException();
    }

    public void a(f fVar) {
        b bVar = this.b;
        b bVar2 = b.DESTROYED;
        if (bVar != bVar2) {
            bVar2 = b.INITIALIZED;
        }
        a aVar = new a(fVar, bVar2);
        if (((a) this.a.f(fVar, aVar)) == null) {
            g gVar = (g) this.c.get();
            if (gVar != null) {
                Object obj = (this.d != 0 || this.e) ? 1 : null;
                Enum b = b(fVar);
                this.d++;
                while (aVar.a.compareTo(b) < 0 && this.a.e.containsKey(fVar)) {
                    this.g.add(aVar.a);
                    aVar.a(gVar, i(aVar.a));
                    g();
                    b = b(fVar);
                }
                if (obj == null) {
                    h();
                }
                this.d--;
            }
        }
    }

    public final b b(f fVar) {
        b.c.a.b.a aVar = this.a;
        b bVar = null;
        c cVar = aVar.e.containsKey(fVar) ? ((c) aVar.e.get(fVar)).d : null;
        b bVar2 = cVar != null ? ((a) cVar.b).a : null;
        if (!this.g.isEmpty()) {
            ArrayList arrayList = this.g;
            bVar = (b) arrayList.get(arrayList.size() - 1);
        }
        return e(e(this.b, bVar2), bVar);
    }

    public void d(b.n.d.a aVar) {
        f(c(aVar));
    }

    public final void f(b bVar) {
        if (this.b != bVar) {
            this.b = bVar;
            if (this.e || this.d != 0) {
                this.f = true;
                return;
            }
            this.e = true;
            h();
            this.e = false;
        }
    }

    public final void g() {
        ArrayList arrayList = this.g;
        arrayList.remove(arrayList.size() - 1);
    }

    /* JADX WARNING: Removed duplicated region for block: B:70:0x0132 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:11:0x002e  */
    public final void h() {
        /*
        r8 = this;
        r0 = r8.c;
        r0 = r0.get();
        r0 = (b.n.g) r0;
        if (r0 == 0) goto L_0x0135;
    L_0x000a:
        r1 = r8.a;
        r2 = r1.d;
        r3 = 0;
        r4 = 1;
        if (r2 != 0) goto L_0x0013;
    L_0x0012:
        goto L_0x0029;
    L_0x0013:
        r2 = r1.a;
        r2 = r2.b;
        r2 = (b.n.h.a) r2;
        r2 = r2.a;
        r5 = r1.b;
        r5 = r5.b;
        r5 = (b.n.h.a) r5;
        r5 = r5.a;
        if (r2 != r5) goto L_0x002b;
    L_0x0025:
        r2 = r8.b;
        if (r2 != r5) goto L_0x002b;
    L_0x0029:
        r2 = 1;
        goto L_0x002c;
    L_0x002b:
        r2 = 0;
    L_0x002c:
        if (r2 != 0) goto L_0x0132;
    L_0x002e:
        r8.f = r3;
        r2 = r8.b;
        r1 = r1.a;
        r1 = r1.b;
        r1 = (b.n.h.a) r1;
        r1 = r1.a;
        r1 = r2.compareTo(r1);
        if (r1 >= 0) goto L_0x00d0;
    L_0x0040:
        r1 = r8.a;
        r2 = new b.c.a.b.b$b;
        r3 = r1.b;
        r5 = r1.a;
        r2.m7846init(r3, r5);
        r1 = r1.c;
        r3 = java.lang.Boolean.FALSE;
        r1.put(r2, r3);
    L_0x0052:
        r1 = r2.hasNext();
        if (r1 == 0) goto L_0x00d0;
    L_0x0058:
        r1 = r8.f;
        if (r1 != 0) goto L_0x00d0;
    L_0x005c:
        r1 = r2.next();
        r1 = (java.util.Map.Entry) r1;
        r3 = r1.getValue();
        r3 = (b.n.h.a) r3;
    L_0x0068:
        r5 = r3.a;
        r6 = r8.b;
        r5 = r5.compareTo(r6);
        if (r5 <= 0) goto L_0x0052;
    L_0x0072:
        r5 = r8.f;
        if (r5 != 0) goto L_0x0052;
    L_0x0076:
        r5 = r8.a;
        r6 = r1.getKey();
        r5 = r5.contains(r6);
        if (r5 == 0) goto L_0x0052;
    L_0x0082:
        r5 = r3.a;
        r6 = r5.ordinal();
        if (r6 == 0) goto L_0x00ca;
    L_0x008a:
        if (r6 == r4) goto L_0x00c4;
    L_0x008c:
        r7 = 2;
        if (r6 == r7) goto L_0x00b2;
    L_0x008f:
        r7 = 3;
        if (r6 == r7) goto L_0x00af;
    L_0x0092:
        r7 = 4;
        if (r6 != r7) goto L_0x0098;
    L_0x0095:
        r5 = b.n.d.a.ON_PAUSE;
        goto L_0x00b4;
    L_0x0098:
        r0 = new java.lang.IllegalArgumentException;
        r1 = new java.lang.StringBuilder;
        r1.<init>();
        r2 = "Unexpected state value ";
        r1.append(r2);
        r1.append(r5);
        r1 = r1.toString();
        r0.<init>(r1);
        throw r0;
    L_0x00af:
        r5 = b.n.d.a.ON_STOP;
        goto L_0x00b4;
    L_0x00b2:
        r5 = b.n.d.a.ON_DESTROY;
    L_0x00b4:
        r6 = c(r5);
        r7 = r8.g;
        r7.add(r6);
        r3.a(r0, r5);
        r8.g();
        goto L_0x0068;
    L_0x00c4:
        r0 = new java.lang.IllegalArgumentException;
        r0.<init>();
        throw r0;
    L_0x00ca:
        r0 = new java.lang.IllegalArgumentException;
        r0.<init>();
        throw r0;
    L_0x00d0:
        r1 = r8.a;
        r1 = r1.b;
        r2 = r8.f;
        if (r2 != 0) goto L_0x000a;
    L_0x00d8:
        if (r1 == 0) goto L_0x000a;
    L_0x00da:
        r2 = r8.b;
        r1 = r1.b;
        r1 = (b.n.h.a) r1;
        r1 = r1.a;
        r1 = r2.compareTo(r1);
        if (r1 <= 0) goto L_0x000a;
    L_0x00e8:
        r1 = r8.a;
        r1 = r1.c();
    L_0x00ee:
        r2 = r1.hasNext();
        if (r2 == 0) goto L_0x000a;
    L_0x00f4:
        r2 = r8.f;
        if (r2 != 0) goto L_0x000a;
    L_0x00f8:
        r2 = r1.next();
        r2 = (java.util.Map.Entry) r2;
        r3 = r2.getValue();
        r3 = (b.n.h.a) r3;
    L_0x0104:
        r4 = r3.a;
        r5 = r8.b;
        r4 = r4.compareTo(r5);
        if (r4 >= 0) goto L_0x00ee;
    L_0x010e:
        r4 = r8.f;
        if (r4 != 0) goto L_0x00ee;
    L_0x0112:
        r4 = r8.a;
        r5 = r2.getKey();
        r4 = r4.contains(r5);
        if (r4 == 0) goto L_0x00ee;
    L_0x011e:
        r4 = r3.a;
        r5 = r8.g;
        r5.add(r4);
        r4 = r3.a;
        r4 = i(r4);
        r3.a(r0, r4);
        r8.g();
        goto L_0x0104;
    L_0x0132:
        r8.f = r3;
        return;
    L_0x0135:
        r0 = new java.lang.IllegalStateException;
        r1 = "LifecycleOwner of this LifecycleRegistry is alreadygarbage collected. It is too late to change lifecycle state.";
        r0.<init>(r1);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.n.h.h():void");
    }
}
